package com.zbkj.admin.controller;

import cn.hutool.core.util.IdUtil;
import com.tiangong.framework.util.HttpsUtils;
import com.tiangong.framework.util.SnowFlakeGenerateIdWorker;
import com.zbkj.admin.service.AdminLoginService;
import com.zbkj.common.request.SystemAdminLoginRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.MenusResponse;
import com.zbkj.common.response.SystemAdminResponse;
import com.zbkj.common.response.SystemLoginResponse;
import com.zbkj.common.utils.CrmebUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 管理端登录服务
 */
@Slf4j
@RestController
@RequestMapping("api/test/v1")
//@Api(tags = "管理端登录服务")
public class TestController {
    //hashmap
    ConcurrentHashMap<Long,DeferredResult<String>> DeferredResultMap=new ConcurrentHashMap(500);

    @GetMapping(value = "/testGet")
    public  DeferredResult<String> testA() {
        DeferredResult<String> result = new DeferredResult<>(10000L);
        long l = IdUtil.getSnowflake(1, 1).nextId();
        System.out.println(l);
        DeferredResultMap.put(l,result);
        result.onTimeout(() -> {
            log.info("调用超时，移除任务，此时队列长度为{}");
        });
        result.onCompletion(() -> {
            log.info("调用完成，移除任务，此时队列长度为{}");
        });
        return result;
    }
    @GetMapping(value = "/testSet")
    public  boolean testB(@RequestParam Long key,@RequestParam String ret) {
        DeferredResult<String> result = DeferredResultMap.get(key);
        result.setResult(ret);
        return true;
    }
}
